package de.tudarmstadt.fgbs.cafe.filesystem;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

import de.tudarmstadt.fgbs.cafe.structure.Fahrplan;

public class FileAutoSaveAgent implements AutoSaveInterface {

    private static final String SAVE_FOLDER = "save";

    @Override
    public void saveCurrentWork(Fahrplan fpl) {
	OutputStream fos = null;

	try {
	    fos = new FileOutputStream(SAVE_FOLDER + File.separator
		    + fpl.getName());
	    ObjectOutputStream os = new ObjectOutputStream(fos);
	    os.writeObject(fpl);
	    fpl.setRevision(fpl.getRevision() + 1);
	} catch (IOException e) {
	    e.printStackTrace();
	} finally {
	    try {
		fos.close();
	    } catch (Exception e) {
		e.printStackTrace();
	    }
	}

    }

    @Override
    public Fahrplan restorePreviousWork(int undoSteps) {
	// TODO Auto-generated method stub
	return null;
    }

}
